import { getProfileAPI } from '@/api/user'

// 导入静态路由
import { routes } from '@/router/index.js'

export default {
  namespaced: true,
  state: {
    // 用户权限标识
    permission: [],
    menuList: []
  },
  mutations: {
    setPermission(state, permission) {
      state.permission = permission
    },
    setMenuList(state, asyncRoutes) {
      state.menuList = [...routes, ...asyncRoutes]
    }
  },
  getters: {},
  actions: {
    async getUserPermission(store) {
      const res = await getProfileAPI()
      store.commit('setPermission', res.data.permissions)
      // 通过return值返回
      return res.data.permissions
    }
  }
}
